package com.qf.pickname.utils;

import cn.hutool.core.io.FileUtil;
import com.qf.pickname.entity.Student;

import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class StudentDataStore {

    public static ArrayList<Student> students = new ArrayList<>();

    public static Integer idgenerator = 1;

    static {
//        List<String> lines = FileUtil.readLines("D:\\studentnames.txt", "UTF-8");
        // 如何获取类加载器对象
        ClassLoader classLoader = StudentDataStore.class.getClassLoader();
        URL resource = classLoader.getResource("studentnames.txt");
        System.out.println(resource);
        List<String> lines = FileUtil.readLines(resource, StandardCharsets.UTF_8);
        for (String line : lines) {
            String[] split = line.split(",");
            String name = split[0];
            String sex = split[1];
            students.add(new Student(idgenerator++,name,sex));
        }

//        students.add(new Student(idgenerator++,"李建男","男"));
//        students.add(new Student(idgenerator++,"解嘉琪","男"));
//        students.add(new Student(idgenerator++,"杨子桐","男"));
//        students.add(new Student(idgenerator++,"吴天久","男"));
//        students.add(new Student(idgenerator++,"王传硕","男"));
    }

}
